package Interview;

import java.util.Scanner;

/**
 * Created by loso on 2017/3/25.
 */
public class _neteasy_2017325Test2 {
        public static void main(String[] args) {
            Scanner in = new Scanner(System.in);
            while (in.hasNextLine()) {//注意while处理多个case
                StringBuilder sb = new StringBuilder(in.nextLine());
                
                int countG = 0;
                int countB = 0;
                int stepG = 0;
                int stepB = 0;

                //算G
                for (int i = 0; i < sb.length(); i++) {
                    if (sb.charAt(i) == 'G'){
                        stepG += i - countG;
                        countG++;
                    }
                }
                //算B
                for (int i = 0; i < sb.length(); i++) {
                    if (sb.charAt(i) == 'B'){
                        stepB += i - countB;
                        countB++;
                    }
                }
                System.out.println(Math.min(stepB,stepG));
            }
        }
}
